package cn.schoolwow.workflow.module.instance.query.flow;

import cn.schoolwow.quickdao.domain.DAO;
import cn.schoolwow.quickdao.domain.database.dql.condition.Condition;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.workflow.entity.WorkFlowInstanceHistory;

import java.util.List;

public class GetWorkFlowInstanceHistoryListFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        Condition condition = flowContext.checkInstanceData(Condition.class);
        DAO dao = flowContext.checkInstanceData(DAO.class);

        dao.addRecordString("工作流实例-查询工作流历史记录");
        List<Long> instanceIdList = condition.addColumn("id").execute().getSingleColumnList(Long.class);
        List<WorkFlowInstanceHistory> list = dao.query(WorkFlowInstanceHistory.class)
                .orderBy("id")
                .addInQuery("workFlowInstanceId", instanceIdList)
                .execute()
                .getList();
        flowContext.putReturnData("list", list);
    }

    @Override
    public String name() {
        return "工作流实例-查询工作流历史记录";
    }

}
